import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    tagList: JSON.parse(localStorage.getItem('tagList') || '[]')
  },
  mutations: {
    delTag (state, val) {
      // console.log(state.tagList)
      state.tagList.splice(state.tagList.indexOf(val), 1)
      // 附加本地储存
      localStorage.setItem('tagList', JSON.stringify(state.tagList))
    },
    addTag (state, val) {
      state.tagList.unshift(val)
      // 附加本地储存
      localStorage.setItem('tagList', JSON.stringify(state.tagList))
    }
  }
})
